/**
 * @author 谭
 * 用户中间间
 */

const db = require('../../db/index');

const returnData = require('../../utils/returnData');

/*
    判断数据库是否已有这个用户
 */
exports.judgeIsUser = (req,res,next) => {
    try {
        const sql = 'select * from user where accounts=?';
        db.query(sql,req.body.accounts,(err,result) => {
            if (err) return returnData(res,500,'错误异常');
            if (result.length !== 0) return returnData(res,400,'用户名已被注册');
            next();
        });
    } catch (e) {
        returnData(res,500,'错误异常')
    }
}


